package com.heima.controller;

import com.heima.common.PageResult;
import com.heima.pojo.Node;
import com.heima.pojo.dto.RegionPageQueryDTO;
import com.heima.pojo.vo.VmVo;
import com.heima.service.NodeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/vm-service/node")
@Slf4j
public class NodeController {

    @Autowired
    private NodeService nodeService;

    @GetMapping("/search")
    public PageResult pageQuery(RegionPageQueryDTO dto){
        PageResult pageResult = nodeService.pageQuery(dto);
        return pageResult;
    }

    @GetMapping("/vmList/{nodeId}")
    public List<VmVo> pageQuery(@PathVariable Long nodeId){
        List<VmVo> vmVoList = nodeService.queryNodeDetails(nodeId);
        return vmVoList;
    }

    /**
     * 新增点位
     * @param node
     * @return
     */
    @PostMapping
    public Boolean insert(@RequestBody Node node){
        nodeService.insert(node);
        return true;
    }

    /**
     * 修改区域
     * @param nodeId
     * @param node
     * @return
     */
    @PutMapping("/{nodeId}")
    public Boolean update(@PathVariable Long nodeId,@RequestBody Node node){
        nodeService.update(nodeId,node);
        return true;
    }
    
}
